#include "AlarmRecord.h"

AlarmRecord::AlarmRecord()
    : m_id(0),
      m_alarmType(StatusChange),
      m_alarmLevel(Info),
      m_paramValue(0.0),
      m_threshold(0.0),
      m_acknowledged(false)
{
}

AlarmRecord::AlarmRecord(const QString &deviceId, AlarmType type, AlarmLevel level)
    : m_id(0),
      m_deviceId(deviceId),
      m_timestamp(QDateTime::currentDateTime()),
      m_alarmType(type),
      m_alarmLevel(level),
      m_paramValue(0.0),
      m_threshold(0.0),
      m_acknowledged(false)
{
}

// 将AlarmType转换为字符串
QString AlarmRecord::alarmTypeString() const
{
    switch (m_alarmType)
    {
    case OverTemperature:
        return "over_temp";
    case OverPressure:
        return "over_pressure";
    case OverFlow:
        return "over_flow";
    case Offline:
        return "offline";
    case Recovered:
        return "recovered";
    case StatusChange:
        return "status_change";
    default:
        return "unknown";
    }
}

// 将AlarmLevel转换为字符串
QString AlarmRecord::alarmLevelString() const
{
    switch (m_alarmLevel)
    {
    case Info:
        return "info";
    case Warning:
        return "warning";
    case Critical:
        return "critical";
    default:
        return "unknown";
    }
}

// 将字符串转换为AlarmType
AlarmRecord::AlarmType AlarmRecord::stringToAlarmType(const QString &str)
{
    if (str == "over_temp")
        return OverTemperature;
    if (str == "over_pressure")
        return OverPressure;
    if (str == "over_flow")
        return OverFlow;
    if (str == "offline")
        return Offline;
    if (str == "recovered")
        return Recovered;
    if (str == "status_change")
        return StatusChange;
    return StatusChange;
}

// 将字符串转换为AlarmLevel
AlarmRecord::AlarmLevel AlarmRecord::stringToAlarmLevel(const QString &str)
{
    if (str == "info")
        return Info;
    if (str == "warning")
        return Warning;
    if (str == "critical")
        return Critical;
    return Info;
}
